package com.klb.service.catalog.impl;

import java.util.ArrayList;
import java.util.List;

import com.klb.dao.impl.BlockDaoImpl;
import com.klb.model.BbsBlock;
import com.klb.service.catalog.BlockServiceCatalog;
import com.klb.tools.Tools;

/**
 * Created by fujia on 2016/6/2.
 */
public class BlockServiceCatalogImpl implements BlockServiceCatalog {
    private BlockDaoImpl blockDao;

    public void setBlockDao(BlockDaoImpl blockDao) {
        this.blockDao = blockDao;
    }


    @Override
    public List<String> getAllTitle() {
        List<String> list = new ArrayList<>();

        for (int i = 1;i <= 6; i++){
            BbsBlock block = this.blockDao.getBlockById(i);

            list.add(!Tools.objectIsNullOrNot(block) ? block.getTitle() : "");
        }

        return list;
    }

    @Override
    public List<String> getAllText() {
        List<String> list = new ArrayList<>();

        for (int i = 1;i <= 6; i++){
            BbsBlock block = this.blockDao.getBlockById(i);

            list.add(!Tools.objectIsNullOrNot(block) ? block.getText() : "");
        }

        return list;
    }

    @Override
    public String getTitleById(int blockId) {
        BbsBlock block = this.blockDao.getBlockById(blockId);
        if (!Tools.objectIsNullOrNot(block)){
            return block.getTitle();
        }

        return null;
    }

    @Override
    public String getTextById(int blockId) {
        BbsBlock block = this.blockDao.getBlockById(blockId);
        if (!Tools.objectIsNullOrNot(block)){
            return block.getText();
        }

        return null;
    }

}
